﻿using System;

namespace MVVMFramework.View
{
    public class InverseBoolConverter : ConverterBase
    {
        protected override object TryConvert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is bool))
                return ReturnFallbackValue(value, targetType);

            // convert
            bool retValue = !(bool)value;

            // reverse
            if (IsReversed)
                retValue = !retValue;

            return retValue;
        }

        protected override object TryConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (!(value is bool))
                return ReturnFallbackValue(value, targetType);

            // convert
            bool retValue = !(bool)value;

            // reverse
            if (IsReversed)
                retValue = !retValue;

            return retValue;
        }
    }
}
